import {Platform, NativeModules, DeviceEventEmitter} from 'react-native';

const RNUpgrade = NativeModules.upgrade;
const ANDROID_PLATFORM = Platform.OS === 'android';

/**
 * 升级 android平台
 * @param apkUrl   android传入apk地址
 */
export const upgrade = (apkUrl) => {
  if (ANDROID_PLATFORM) {
    RNUpgrade.upgrade(apkUrl);
  }
};

/**
 * android apk下载回调
 * @param callBack
 */
export const addDownLoadListener = (callBack) => {
  if (ANDROID_PLATFORM) {
    return DeviceEventEmitter.addListener('LOAD_PROGRESS', callBack);
  }
};

export const addDownLoadSuccessListener = (callBack) => {
  if (ANDROID_PLATFORM) {
    return DeviceEventEmitter.addListener('DOWNLOAD_SUCCESS', callBack);
  }
};
